package flexo.file.writer;

import java.io.BufferedWriter;
import java.io.IOException;

import flexo.file.Node;
import flexo.file.Property;


public class Config extends Writer
{
	@Override
	public void write(Node fileNode)
	{
		try
		{					
			BufferedWriter sw = createBufferedWriter(fileNode.name);
	
			for (int pos = 0; pos < fileNode.getChildrenCount(); pos++)
			{
				Node currentNode = fileNode.getChild(pos);
				sw.write("[" + currentNode.name + "]");
				sw.newLine();
				for (int pPos = 0; pPos < currentNode.getPropertyCount(); pPos++)
				{
					Property currentProperty = currentNode.getProperty(pPos);
					sw.write(currentProperty.name + "=" + currentProperty.getStringValue());
					sw.newLine();
				}
				sw.newLine();
			}
	
			sw.close();
		}
		catch(IOException ioe)
		{
			writeError(fileNode.name);
		}
	}

}
